<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <title>Document</title>
</head>
<body>
    
    <div id="app">
        <p>{{number}}</p>
        <my-component @my-click="myclick"></my-component>
    </div>

    <script>

        Vue.component("my-component",{
            template:`
            <div>
                <p>{{num}}</p>
                <button @click="click">点击增加</button>
            </div>
            `,
            data(){
                return {
                    num:0
                }
            },
            methods:{
                click(){
                    this.num++
                    this.$emit("my-click",this.num)
                }
            }
        })

        new Vue({
            el:"#app",
            data:{
                number:0
            },
            methods:{
                myclick(n){
                    this.number = n
                }
            }
        })
    </script>
</body>
</html>